﻿package com.colorsstudio.defence.baseClass 
{
	import com.colorsstudio.defence.ConstantValues.Constants;
	import com.colorsstudio.defence.Levels.gameScene1;
	import com.colorsstudio.defence.Levels.Level;
	import flash.display.DisplayObject;
	import flash.display.SimpleButton;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	/**
	 * ...
	 * @author wuzhida
	 */
	public class PopUpSettingWindow extends Sprite implements IPopUpWindow 
	{
		public var bg:Sprite;
		public var slide:Slide;
		public var _mainMenuButton:SimpleButton;
		public var _continueButton:SimpleButton;
		public var _restartButton:SimpleButton;
		public var _cancelButton:SimpleButton;
		public var mParentScene:Level;
		
		public function PopUpSettingWindow() 
		{
			mParentScene = Constants.CURRENT_SCENE;
			bg = new Sprite();
			bg.graphics.beginFill(0xffffff, .7);
			bg.graphics.drawRect(0, 0, Constants.SCREEN_WIDTH, Constants.SCREEN_HEIGHT);
			bg.graphics.endFill();
			
			slide = new Slide("Sound");
			slide.x = Constants.SCREEN_WIDTH / 2 - slide._bg.width / 2;
			slide.y = Constants.SCREEN_HEIGHT / 2  -slide._bg.height / 2;
			
			initD();
			
			this.addChild(bg);
			this.addChild(slide);		
			this.slide.addChild(_mainMenuButton);
			this.slide.addChild(_continueButton);
			this.slide.addChild(_restartButton);
			this.slide.addChild(_cancelButton);
			
		}
		
		public function initD():void 
		{
			
			_mainMenuButton = new f_mainMenuButton();
			_mainMenuButton.x = slide._bg.width / 2;
			_mainMenuButton.y = slide._bg.height / 2 + 2*Constants.POPUPWIN_OFFSET;
			
			_continueButton = new f_continueButton();
			_continueButton.x = 3*Constants.POPUPWIN_OFFSET+_continueButton.width/2;
			_continueButton.y = _mainMenuButton.y + Constants.POPUPWIN_OFFSET * 2;
			
			_restartButton = new f_restartButton();
			_restartButton.x = slide._bg.width - _restartButton.width - Constants.POPUPWIN_OFFSET;
			_restartButton.y = _mainMenuButton.y + Constants.POPUPWIN_OFFSET * 2;
			
			_cancelButton = new f_btnCancel();
			_cancelButton.x = slide._bg.width -  Constants.POPUPWIN_OFFSET;;
			_cancelButton.y = _cancelButton.height;	
			
			_cancelButton.addEventListener(MouseEvent.CLICK, closeWindow1,false,0,true);
			_continueButton.addEventListener(MouseEvent.CLICK, closeWindow1,false,0,true);
			_restartButton.addEventListener(MouseEvent.CLICK, restartScene,false,0,true);
			_mainMenuButton.addEventListener(MouseEvent.CLICK, mainMenu,false,0,true);
		}
		
		private function mainMenu(e:MouseEvent):void 
		{
			mParentScene.mainMenu();
		}
		
		private function restartScene(e:MouseEvent):void 
		{
			mParentScene.restartGame();
		}
		
		private function closeWindow1(e:MouseEvent):void 
		{
			closeWindow();
		}
		
		/* INTERFACE com.colorsstudio.defence.baseClass.IPopUpWindow */
		
		public function pauseGameScene():void 
		{
			
		}
		
		public function showWindow(parent:DisplayObject):void 
		{
			
		}
		
		public function closeWindow():void 
		{
			if (mParentScene.flag)
			{
				mParentScene.pauseGame();
			}
			this.parent.removeChild(this);
		}
		
	}

}